package cn.stronglink.asset.module.resource.resource.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.toolkit.IdWorker;

import cn.stronglink.asset.model.Resource;
import cn.stronglink.asset.module.resource.resource.mapper.ResourceMapper;
import cn.stronglink.suite.core.util.WebUtil;
@Service
@Transactional(rollbackFor = Exception.class)
public class ResourceService {
	
	@Autowired
	private ResourceMapper resourceMapper;
	
	public void create(Resource resource) {
		if(resource.getId()==null) {
			resource.setId(IdWorker.getId());
		}
		resource.setCreateBy(WebUtil.getCurrentUser());
		resource.setCreateTime(new Date());
		resourceMapper.create(resource);
	}

	public void edit(Resource resource) {
		resource.setUpdateBy(WebUtil.getCurrentUser());
		resource.setCreateTime(new Date());
		resourceMapper.update(resource);
	}

	public void remove(Long id) {
		resourceMapper.remove(id);
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public Resource qryById(Long id) {
		return resourceMapper.qryById(id);
	}
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public Page<Resource> qryList(Page<Resource> page, Map<String, Object> params) {
		List<Resource> list = resourceMapper.qryList(page,params);
		page.setRecords(list);
		return page;
	}
	

}
